<html>
<head><meta charset="utf-8"><title>Formatting · project-inline-asm · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/index.html">project-inline-asm</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Formatting.html">Formatting</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="186314584"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Formatting/near/186314584" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Formatting.html#186314584">(Jan 22 2020 at 18:23)</a>:</h4>
<p>I don't think we should do this in the current RFC (because I don't want to introduce a topic that leads to bikeshedding), but I think we should post a PR to <a href="https://github.com/rust-dev-tools/fmt-rfcs/" target="_blank" title="https://github.com/rust-dev-tools/fmt-rfcs/">https://github.com/rust-dev-tools/fmt-rfcs/</a> that proposes how to format <code>asm!</code> blocks.</p>



<a name="186314761"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Formatting/near/186314761" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Formatting.html#186314761">(Jan 22 2020 at 18:24)</a>:</h4>
<p>Proposal:<br>
Format on one line if it fits the line length. If it's long enough to break across lines, then format it as you would format a function with arguments, except that options should appear on the same line, and multiple operand specifications should appear on the same line unless they don't fit within the line length, in which case one operand should appear per line.</p>



<a name="186314881"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Formatting/near/186314881" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Formatting.html#186314881">(Jan 22 2020 at 18:25)</a>:</h4>
<p>We should also specify how to format a multi-line asm string.</p>



<a name="186315074"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Formatting/near/186315074" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Formatting.html#186315074">(Jan 22 2020 at 18:27)</a>:</h4>
<p>I expect multi-line asm to  be very common.</p>



<a name="186315099"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Formatting/near/186315099" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Formatting.html#186315099">(Jan 22 2020 at 18:27)</a>:</h4>
<p>Also use of <code>concat!()</code> in the asm string.</p>



<a name="186315352"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Formatting/near/186315352" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Formatting.html#186315352">(Jan 22 2020 at 18:29)</a>:</h4>
<p>So:</p>
<div class="codehilite"><pre><span></span><span class="n">asm</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;short asm {}&quot;</span><span class="p">,</span><span class="w"> </span><span class="k">in</span><span class="p">(</span><span class="n">reg</span><span class="p">)</span><span class="w"> </span><span class="n">input_value</span><span class="p">);</span><span class="w"></span>

<span class="n">asm</span><span class="o">!</span><span class="p">(</span><span class="w"></span>
<span class="w">    </span><span class="s">&quot;longer asm {x} {y} {z}&quot;</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">in</span><span class="p">(</span><span class="n">reg</span><span class="p">)</span><span class="w"> </span><span class="n">expr1</span><span class="p">,</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">in</span><span class="p">(</span><span class="n">reg</span><span class="p">)</span><span class="w"> </span><span class="n">expr2</span><span class="p">,</span><span class="w"> </span><span class="n">z</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">out</span><span class="p">(</span><span class="n">reg</span><span class="p">)</span><span class="w"> </span><span class="n">expr3</span><span class="p">,</span><span class="w"></span>
<span class="p">);</span><span class="w"></span>

<span class="n">asm</span><span class="o">!</span><span class="p">(</span><span class="w"></span>
<span class="w">    </span><span class="s">&quot;longer asm {x} {y} {z}&quot;</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">in</span><span class="p">(</span><span class="n">reg</span><span class="p">)</span><span class="w"> </span><span class="n">long_expression_1</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">in</span><span class="p">(</span><span class="n">reg</span><span class="p">)</span><span class="w"> </span><span class="n">long_expression_2</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">z</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">out</span><span class="p">(</span><span class="n">reg</span><span class="p">)</span><span class="w"> </span><span class="n">long_destination_3</span><span class="p">,</span><span class="w"></span>
<span class="p">);</span><span class="w"></span>
</pre></div>



<a name="186315539"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Formatting/near/186315539" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Formatting.html#186315539">(Jan 22 2020 at 18:30)</a>:</h4>
<p>(Note the trailing commas, just like a multi-line function call.)</p>



<a name="186316087"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Formatting/near/186316087" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Formatting.html#186316087">(Jan 22 2020 at 18:36)</a>:</h4>
<p>LGTM</p>



<a name="186316176"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Formatting/near/186316176" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Formatting.html#186316176">(Jan 22 2020 at 18:36)</a>:</h4>
<p>For multi-line assembly text, the quotes surrounding the asm string may be treated like delimiters, and shouldn't be put on the same lines as assembly text:</p>
<div class="codehilite"><pre><span></span><span class="n">asm</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;</span>
<span class="s">    multi-line assembly</span>
<span class="s">    with multiple instructions</span>
<span class="s">    but no operands</span>
<span class="s">&quot;</span><span class="p">);</span><span class="w"></span>

<span class="n">asm</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;</span>
<span class="s">    multi-line {x}</span>
<span class="s">    with operands {y}</span>
<span class="s">    &quot;</span><span class="p">,</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">in</span><span class="p">(</span><span class="n">reg</span><span class="p">)</span><span class="w"> </span><span class="n">expr</span><span class="p">,</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">out</span><span class="p">(</span><span class="n">reg</span><span class="p">)</span><span class="w"> </span><span class="n">dest</span><span class="p">,</span><span class="w"></span>
<span class="p">);</span><span class="w"></span>
</pre></div>



<a name="186316178"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Formatting/near/186316178" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Formatting.html#186316178">(Jan 22 2020 at 18:36)</a>:</h4>
<p>One thing I'm not too happy about is how to make the actual asm string look good when it is split over multiple lines</p>



<a name="186316270"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Formatting/near/186316270" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Formatting.html#186316270">(Jan 22 2020 at 18:37)</a>:</h4>
<p>(I'm not certain about the multi-line with operands case; perhaps the closing quote in that case shouldn't be on the same line as the operands.)</p>



<a name="186316287"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Formatting/near/186316287" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Formatting.html#186316287">(Jan 22 2020 at 18:37)</a>:</h4>
<p>(But it seems the least bad of several possibilities there.)</p>



<a name="186316418"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Formatting/near/186316418" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Formatting.html#186316418">(Jan 22 2020 at 18:38)</a>:</h4>
<p>It helps that we don't especially care about the indentation of the emitted assembly, so we don't need things like <code>\n\</code> or <code>\n\t\</code> on every line.</p>



<a name="186316483"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Formatting/near/186316483" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Formatting.html#186316483">(Jan 22 2020 at 18:39)</a>:</h4>
<p>It bugs me that the indentation of the closing <code>"</code> differs between the operand case and the no-operand case, though.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>